package org.smr.ministore.micro.client;

import org.blade.msg.ErrorCode;
import org.blade.utils.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smr.ministore.entities.GoodsSpecification;
import org.smr.ministore.entities.vo.Assign2OrganVO;
import org.smr.ministore.entities.vo.Assign2OrgansVO;
import org.springframework.stereotype.Component;

import java.util.List;

import feign.hystrix.FallbackFactory;


@Component
public class HystrixGoodsSpecificationClientFactory implements FallbackFactory<FeignGoodsSpecificationMicroServiceClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixGoodsSpecificationClientFactory.class);

    @Override
    public FeignGoodsSpecificationMicroServiceClient create(Throwable cause) {
        HystrixGoodsSpecificationClientFactory.LOGGER.info("fallback; reason was: {}", cause.getMessage());

        return new FeignGoodsSpecificationMicroServiceClient() {

            @Override
            public int batchSave(List<GoodsSpecification> entities) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public int batchModify(List<GoodsSpecification> entities) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public int save(GoodsSpecification entity) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public int updateById(GoodsSpecification id) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public GoodsSpecification queryById(Long id) {
                GoodsSpecification goodsSpecification = new GoodsSpecification();
                goodsSpecification.setId(ErrorCode.Rpc.FUSING_DEFAULT_ID);
                return goodsSpecification;
            }

            @Override
            public int deleteById(Long id) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public Pager<GoodsSpecification> paginate(GoodsSpecification entity, Long pageSize, Long pageNum) {
                Pager<GoodsSpecification> pager = new Pager<GoodsSpecification>();
                pager.setCurrentPage(ErrorCode.Rpc.FUSING_DEFAULT_PAGER);
                pager.setTotalCount(ErrorCode.Rpc.FUSING_DEFAULT_PAGER);
                pager.setPageSize(ErrorCode.Rpc.FUSING_DEFAULT_PAGER);
                return pager;
            }

            @Override
            public int assign(Assign2OrgansVO assignee) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public int deleteByIdLogical(Long id) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public int assign(Assign2OrganVO goodsAssign2Organ) {
                return ErrorCode.Rpc.FUSING;
            }

            @Override
            public GoodsSpecification queryByPrimaryKey(GoodsSpecification goodsSpecification) {
                goodsSpecification = new GoodsSpecification();
                goodsSpecification.setId(ErrorCode.Rpc.FUSING_DEFAULT_ID);
                return goodsSpecification;
            }

        };//Return end
    }
}